<template>
  <div class="newsdetail">
    <h3 class="title">{{newsinfo.title}}</h3>
    <p class="subtitle">
      <span>发表时间：{{newsinfo.add_time | dataFormat}}</span>
      <span>点击：{{newsinfo.click}}</span>
    </p>
    <hr />
    <div class="content" v-html="newsinfo.content"></div>
    <comment-box :id="this.id"></comment-box>
  </div>
</template>

<script>
import comments from "./comments.vue";
export default {
  data() {
    return {
      newsinfo: {},
      id: this.$route.params.id
    };
  },
  created() {
    this.getNews();
  },
  methods: {
    getNews() {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getnew/" + this.id)
        .then(result => {
          if (result.body.status === 0) {
            this.newsinfo = result.body.message[0];
          } else {
            Toast("新闻详情加载失败");
          }
        });
    }
  },
  components: {
    "comment-box": comments
  }
};
</script>

<style lang="scss">
.newsdetail {
  padding: 0 4px;

  .title {
    text-align: center;
    font-size: 15px;
    margin: 0 15px;
  }

  .subtitle {
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    color: blue;
  }
  .content {
    img {
      width: 100%;
    }
  }
}
</style>